package stack;

public class BackspaceCompare {
    public static boolean code(String s, String t) {
        //处理两个字符串
        String s1 = backString(s);
        String s2 = backString(t);
        if (s1.equals(s2)){
            return true;
        }else {
            return false;
        }
    }

    public static String backString(String str){
        StringBuffer ret = new StringBuffer();
        char[] s = str.toCharArray();

        for (char ch : s){
            if (ret.length() >= 0 && ch == '#'){
                if (ret.length() > 0){
                    ret.deleteCharAt(ret.length() - 1);
                }
            }else{
                ret.append(ch);
            }
        }

        return ret.toString();
    }

    public static void main(String[] args) {
        BackspaceCompare.code("a##c", "#a#c");
    }
}
